/*
 * Copyright 2011 es-planning Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package jp.arctos.ursus.extension.net;

import java.io.IOException;
import java.net.SocketAddress;
import java.net.SocketException;

/**
 * Handler for the server socket session.
 * 
 */
public class ServerSocketSessionHandler {

	/** Server socket session. */    
    ServerSocketSession session;

    /**
     * Constructor.
     * 
     * @param session Session
     * @throws IOException
     */
    public ServerSocketSessionHandler(ServerSocketSession session) throws IOException {
        this.session = session;
    }

    /**
     * Get the bound local host address.
     * 
     * @return Local host address
     */
    public SocketAddress getLocalAddress() {
        return session.getLocalAddress();
    }

    /**
     * Close session.
     * 
     */
    public void close() {
        session.closeSession();
    }

    /**
     * Get value of SO_RCVBUF socket option.
     * 
     * @return SO_RCVBUF Socket option
     * @throws SocketException 
     * @see java.net.ServerSocket#getReceiveBufferSize()
     */
    public int getReceiveBufferSize() throws SocketException {
        return session.getReceiveBufferSize();
    }

    /**
     * Get value of SO_REUSEADDR socket option.
     * 
     * @return SO_REUSEADDR Socket option
     * @throws SocketException 
     * @see java.net.ServerSocket#getReuseAddress()
     */
    public boolean getReuseAddress() throws SocketException {
        return session.getReuseAddress();
    }

    /**
     * Get value of SO_TIMEOUT socket option.
     * 
     * @return SO_TIMEOUT Socket option
     * @throws IOException 
     * @see java.net.ServerSocket#getSoTimeout()
     */
    public int getSoTimeout() throws IOException {
        return session.getSoTimeout();
    }

    /**
     * Configure SO_TIMEOUT socket option.
     * 
     * @param timeout SO_TIMEOUT Socket option
     * @throws SocketException 
     * @see java.net.ServerSocket#setSoTimeout(int)
     */
    public void setSoTimeout(int timeout) throws SocketException {
        session.setSoTimeout(timeout);
    }
}
